<template>
  <div>
    <el-card class="search_box">
      <div slot="header" class="clearfix">
        <span>查询条件</span>
        <el-button style="float: right; padding: 3px 0" @click="showAdvanced"
                   v-bind:class="[searchBox.advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down']" type="text">展开高级查询</el-button>
      </div>
      <el-form size="mini" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card>
      <div slot="header" class="clearfix">
        <div style="display: flex;display: flex;flex-flow: row nowrap;justify-content: space-between;">
          <div>
            <el-button size="mini" class="el-button--black" icon="el-icon-refresh"></el-button>
            <el-button size="mini" v-if="isAuth('bid:project:save')" type="primary" @click="newHandle()">新增</el-button>
            <el-button size="mini" v-if="isAuth('bid:project:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
          </div>
          <div>
            <el-button-group>
              <el-dropdown :hide-on-click="false">
                <el-button size="mini" icon="el-icon-arrow-down el-icon--right">列</el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>
                    <el-checkbox v-model="checked">备选项</el-checkbox>
                  </el-dropdown-item>
                  <el-dropdown-item>狮子头</el-dropdown-item>
                  <el-dropdown-item>螺蛳粉</el-dropdown-item>
                  <el-dropdown-item>双皮奶</el-dropdown-item>
                  <el-dropdown-item>蚵仔煎</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-button size="mini" v-if="isAuth('bid:question:save')" icon="el-icon-s-unfold" @click="addOrUpdateHandle()">导出</el-button>
              <el-button size="mini" v-if="isAuth('bid:question:delete')" icon="el-icon-s-fold" @click="deleteHandle()">导入</el-button>
            </el-button-group>
          </div>
        </div>
      </div>
      <el-table
        size="mini"
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50">
        </el-table-column>
        <el-table-column
          prop="id"
          header-align="center"
          align="center"
          label="">
        </el-table-column>
        <el-table-column
          prop="projectCode"
          header-align="center"
          align="center"
          label="项目编号">
        </el-table-column>
        <el-table-column
          prop="projectName"
          header-align="center"
          align="center"
          label="项目名称">
        </el-table-column>
        <el-table-column
          prop="tradeTypeId"
          header-align="center"
          align="center"
          label="行业类别ID">
        </el-table-column>
        <el-table-column
          prop="tradeTypeName"
          header-align="center"
          align="center"
          label="行业类别名称">
        </el-table-column>
        <el-table-column
          prop="projectTypeOneId"
          header-align="center"
          align="center"
          label="项目一级分类ID">
        </el-table-column>
        <el-table-column
          prop="projectTypeOneName"
          header-align="center"
          align="center"
          label="项目一级分类名称">
        </el-table-column>
        <el-table-column
          prop="projectTypeTwoId"
          header-align="center"
          align="center"
          label="项目二级分类ID">
        </el-table-column>
        <el-table-column
          prop="projectTypeTwoName"
          header-align="center"
          align="center"
          label="项目二级分类名称">
        </el-table-column>
        <el-table-column
          prop="entrustId"
          header-align="center"
          align="center"
          label="委托单ID">
        </el-table-column>
        <el-table-column
          prop="contractId"
          header-align="center"
          align="center"
          label="合同ID">
        </el-table-column>
        <el-table-column
          prop="projectManagerId"
          header-align="center"
          align="center"
          label="项目经理ID">
        </el-table-column>
        <el-table-column
          prop="projectManager"
          header-align="center"
          align="center"
          label="项目经理名称">
        </el-table-column>
        <el-table-column
          prop="feeServer"
          header-align="center"
          align="center"
          label="服务对象">
        </el-table-column>
        <el-table-column
          prop="feeMethod"
          header-align="center"
          align="center"
          label="服务费收取方式">
        </el-table-column>
        <el-table-column
          prop="projectBlock"
          header-align="center"
          align="center"
          label="项目板块">
        </el-table-column>
        <el-table-column
          prop="supervision"
          header-align="center"
          align="center"
          label="监督部门">
        </el-table-column>
        <el-table-column
          prop="feeSourceId"
          header-align="center"
          align="center"
          label="资金来源ID">
        </el-table-column>
        <el-table-column
          prop="feeSource"
          header-align="center"
          align="center"
          label="资金来源：财政资金、企业自筹、其他">
        </el-table-column>
        <el-table-column
          prop="needPurchase"
          header-align="center"
          align="center"
          label="是否需要购标,可选需要、不需要">
        </el-table-column>
        <el-table-column
          prop="budget"
          header-align="center"
          align="center"
          label="项目概算, 标段预算/概算价之和">
        </el-table-column>
        <el-table-column
          prop="scheduleId"
          header-align="center"
          align="center"
          label="年度计划ID">
        </el-table-column>
        <el-table-column
          prop="scheduleName"
          header-align="center"
          align="center"
          label="年度计划">
        </el-table-column>
        <el-table-column
          prop="tendereeId"
          header-align="center"
          align="center"
          label="招标人ID">
        </el-table-column>
        <el-table-column
          prop="tendereeName"
          header-align="center"
          align="center"
          label="招标人">
        </el-table-column>
        <el-table-column
          prop="bidScope"
          header-align="center"
          align="center"
          label="招标内容与范围">
        </el-table-column>
        <el-table-column
          prop="bidContent"
          header-align="center"
          align="center"
          label="招标项目规模及概况">
        </el-table-column>
        <el-table-column
          prop="province"
          header-align="center"
          align="center"
          label="省直辖市">
        </el-table-column>
        <el-table-column
          prop="city"
          header-align="center"
          align="center"
          label="地市区县">
        </el-table-column>
        <el-table-column
          prop="bidMethod"
          header-align="center"
          align="center"
          label="招标方式">
        </el-table-column>
        <el-table-column
          prop="openMethod"
          header-align="center"
          align="center"
          label="开标方式">
        </el-table-column>
        <el-table-column
          prop="openStep"
          header-align="center"
          align="center"
          label="开标步制">
        </el-table-column>
        <el-table-column
          prop="needApprove"
          header-align="center"
          align="center"
          label="是否报名审核">
        </el-table-column>
        <el-table-column
          prop="approveMethod"
          header-align="center"
          align="center"
          label="资格审查方式">
        </el-table-column>
        <el-table-column
          prop="evaluateMethod"
          header-align="center"
          align="center"
          label="评标方式">
        </el-table-column>
        <el-table-column
          prop="submitMethod"
          header-align="center"
          align="center"
          label="评标文件递交方式">
        </el-table-column>
        <el-table-column
          prop="remark"
          header-align="center"
          align="center"
          label="备注">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="dashboardHandle(scope.row.id)">主控台</el-button>
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
            <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './project-add-or-update'
  export default {
    data () {
      return {
        searchBox: {
          advanced: false
        },
        dataForm: {
          key: ''
        },
        checked: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bid/project/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      dashboardHandle () {
        this.$router.push({
          path: '/bid/project-dashboard'
        })
      },
      newHandle (id) {
        this.$router.push({
          path: '/bid/project-edit'
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/bid/project/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 切换高级查询
      showAdvanced () {
        this.searchBox.advanced = !this.searchBox.advanced
      }
    }
  }
</script>
